package demo22;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

public class UseTimer {
    public static void main(String[] args) throws InterruptedException {
        Timer timer = new Timer();
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                System.out.println("你好世界");
            }
        };
        // timer.schedule(task, 5000);
        timer.scheduleAtFixedRate(task, 3000, 2000);

        while (true) {
            System.out.println("我是主线程");
            TimeUnit.SECONDS.sleep(1);
        }

    }
}
